﻿using UnityEngine;
using System.Collections;

public class EnemySpawner : MonoBehaviour {

	public GameObject EnemyObject;
	public float spawnTimer;
	public float initialSpawnTimer = 2f;
	public float spacer;
	public float enemyp;
	public GameObject Trunk;
	
	// Use this for initialization
	void Start () {
		this.spawnTimer = this.initialSpawnTimer;
		this.spacer = 5;
		this.SpawnTrunk ();
	}

	// Update is called once per frame
	void Update () {
		this.spawnTimer -= Time.deltaTime;
		if (this.spawnTimer < 0) 
		{
			this.SpawnTrunk();
			this.resetTimer();
		}
	}
	
	private void SpawnTrunk()
	{
		//enemyp = 0;
		enemyp = Random.Range(0,360);
		Debug.Log(enemyp);
		Instantiate (this.EnemyObject, new Vector3 (Mathf.Cos((Mathf.PI/180)*enemyp)*this.Trunk.transform.localScale.x/2, 1 + Mathf.Sin((Mathf.PI/180)*enemyp)*this.Trunk.transform.localScale.y/2, this.spacer), Quaternion.Euler (0f, 0f, enemyp+90));
		this.spacer += 5;
	}
	
	private void resetTimer(){
		this.spawnTimer = this.initialSpawnTimer;
	}
	
}


